Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-56927] Implementation of credentials for private SSH keys used by EC2 plugin #445

Merged
merged 51 commits into from
Aug 25, 2020

Conversation

djesionek
Copy link
Contributor

This should fix the issue described in JENKINS-56927.

I tried to keep as much of the credential logic itself contained inside the EC2Cloud class but still in a way that the private key itself is not being stored longer than necessary outside of the credential API.

This implementation also takes care of migrating the old plaintext ssh configuration to the credentials API. This was checked in a test environment and also the unit tests themselves are not modified more than necessary and some of them still relied on the old storage method and a migration is performed in each one.
In my tests the privateKey was still included in plaintext in the CasC yaml when exporting, so I managed to find a quite hacky solution for that by returning null in the getter and creating a static method resolving the credential of a EC2Cloud object to a EC2PrivateKey which is now used instead in all places. If there is a better way for that I have not found it yet...

All of this introduced one new dependency: org.jenkins-ci.plugins:ssh-credentials:1.14
As the aws-credentials plugin has a different dependency to the credentials package it also was fixed to be min version 2.1.17 to prevent dependency errors. I have not checked how low we could go here but I'm also not sure how important this might be here.

Eucalyptus implementations also were updated accordingly with this but could not be tested explicitly due to lack of a test environment on my side.

djesionek and others added 20 commits March 13, 2020 16:59
…key is prevented to be showed in CasC export
@djesionek
Copy link
Contributor Author

Hi @jvz and @res0nance ,
should I have assigned anyone from you maintainers as reviewer for this PR to be picked up or is something else missing?

@jvz
Copy link
Member

jvz commented Apr 8, 2020

Ooh, this looks nice! I've added some people as reviewers to look through this.

@Wadeck
Copy link

Wadeck commented Apr 8, 2020

(I will not have the time to review it, sorry)

pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java Outdated Show resolved Hide resolved
src/main/java/hudson/plugins/ec2/Eucalyptus.java Outdated Show resolved Hide resolved
@djesionek djesionek requested a review from res0nance May 27, 2020 15:33
@froblesmartin
Copy link
Member

What is missing on this PR to be merged? @djesionek @markyjackson-taulia

@djesionek
Copy link
Contributor Author

AFAIK I adressed all the requested changes from the reviewers that reviewed this PR. I'm just waiting for either feedback or a merge.
Maybe @res0nance can tell what is missing.

@froblesmartin
Copy link
Member

froblesmartin commented Jul 10, 2020

AFAIK I adressed all the requested changes from the reviewers that reviewed this PR. I'm just waiting for either feedback or a merge.
Maybe @res0nance can tell what is missing.

Well, I have just seen that at least what you can see below, there is a conflict on the EC2Cloud.java file

@djesionek
Copy link
Contributor Author

Thanks for the info, that one seems to be new. I won't be able to resolve it until Sunday probably.

@djesionek
Copy link
Contributor Author

Can someone tell me what's missing to get the reviews processed?

@froblesmartin
Copy link
Member

@djesionek FYI in https://issues.jenkins-ci.org/browse/SECURITY-1883 @daniel-beck asked @jetersen to have a look into this.

@djesionek
Copy link
Contributor Author

@froblesmartin thanks for the info somehow my jenkins community account got lost that's probably why I missed that.

@jetersen
Copy link
Member

not sure what I can assist with.

@djesionek
Copy link
Contributor Author

And I'm not sure what is missing for getting this merged other than maybe further reviews when necessary. Maybe @daniel-beck knows more?

@jvz
Copy link
Member

jvz commented Aug 24, 2020

This plugin needs active maintainers. I've re-added the adopt-this-plugin label as this hasn't received new maintainers since I thought I last added that.

@froblesmartin
Copy link
Member

This plugin needs active maintainers. I've re-added the adopt-this-plugin label as this hasn't received new maintainers since I thought I last added that.

@jvz I have been thinking since a while about maintaining a plugin to start contributing. This could be a perfect moment 😋 .

Following https://www.jenkins.io/doc/developer/plugin-governance/adopt-a-plugin/, I am going to send an email to the DL requesting access 👍

@res0nance res0nance added the enhancement Feature additions or enhancements label Aug 25, 2020
@res0nance res0nance merged commit 8702cc4 into jenkinsci:master Aug 25, 2020
@djesionek
Copy link
Contributor Author

Thanks, hope it gets released soon 😄

@batmat
Copy link
Member

batmat commented Sep 14, 2020

@res0nance @MRamonLeon @fcojfernandez @froblesmartin could you please consider doing a release for this? Thanks!

@MRamonLeon
Copy link
Contributor

@varyvol
Copy link

varyvol commented Sep 16, 2020

How was migration tested here? I had one EC2 cloud configured with 1.50.3 and when updated to 1.52, the cloud is there but no credentials are in place for the private key. Also an error is displayed because the "doCheckSshKeysCredentialsId" requires POST and the validation performed when the credential is selected is not using that.

@MRamonLeon
Copy link
Contributor

^ @res0nance

this.sshKeysCredentialsId = sshKeysCredentialsId;

if (this.sshKeysCredentialsId == null && ( this.privateKey != null || privateKey != null)){
migratePrivateSshKeyToCredential(this.privateKey != null ? this.privateKey.getPrivateKey() : privateKey);
Copy link
Member

@daniel-beck daniel-beck Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A migration call in the constructor makes no sense. This should be in readResolve. This was probably never tested with existing stored data.

@djesionek
Copy link
Contributor Author

I made a PR with a fix for that and retested the migration scenario there manually. Maybe it would be good to create an automated test for that but at this point I have no clue how this could be achieved 😄
Sorry that I missed this!

@erik-hakansson-wcar
Copy link

This broke our setup as the old key wasn't migrated.

@varyvol
Copy link

varyvol commented Sep 18, 2020

ec2-1.53 fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature additions or enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.